package ch10_thread.thread;

import cn.hutool.core.date.DateUtil;

import java.util.concurrent.TimeUnit;

/**
 *
 * 1、被中断
 * 2、sleep写法
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class SleepInterRuptep implements Runnable {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new SleepInterRuptep());
        thread.start();
        Thread.sleep(5000);
        thread.interrupt();
    }

    @Override
    public void run() {
        while (true) {
            System.out.println(DateUtil.now());
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                System.out.println("被中断...");
                e.printStackTrace();
            }
        }
    }
}
